import sys

from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QFrame, QVBoxLayout, QHBoxLayout, \
    QCheckBox

'''
复选框使用QCheckBox()
stateChanged 改变信号为int 0未勾选 2已勾选
self.sender().text()  # 对象.sender()方法区分控件 名称
'''


class MyClass(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程')
        self.setGeometry(800, 370, 400, 300)

        myFrame = QFrame(self)
        self.ck1 = QCheckBox('跳舞', myFrame)
        self.ck1.stateChanged[int].connect(self.myState)  # 复选框改变信号为int 0未勾选 2已勾选
        self.ck2 = QCheckBox('唱歌', myFrame)
        self.ck2.stateChanged[int].connect(self.myState)
        self.ck2.move(0, 30)

        self.lbl = QLabel('', myFrame)
        self.lbl.move(65, 18)

        myFrame.move(50, 50)

        self.show()

    def myState(self, i):
        # print(i)  # 0  2
        c = '已选中-' if i else '已取消-'
        s = self.sender()  # 对象.sender()方法区分
        self.lbl.setText(c + s.text())
        self.lbl.adjustSize()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    app.exec_()
